


<!DOCTYPE html>
<html id="htmlId">
<head>
  <title>Coverage Report > Board</title>
  <style type="text/css">
    @import "../../css/coverage.css";
    @import "../../css/idea.min.css";
  </style>
  <script type="text/javascript" src="../../js/highlight.min.js"></script>
  <script type="text/javascript" src="../../js/highlightjs-line-numbers.min.js"></script>
</head>

<body>
<div class="content">
<div class="breadCrumbs">
Current scope:     <a href="../../index.html">all classes</a>
    <span class="separator">|</span>
    <a href="../index.html">nl.tudelft.jpacman.board</a>
</div>

<h1>Coverage Summary for Class: Board (nl.tudelft.jpacman.board)</h1>

<table class="coverageStats">
<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Class, %
</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">Board</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (1/1)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (7/7)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    94.4%
  </span>
  <span class="absValue">
    (17/18)
  </span>
</td>
</tr>

</table>

<br/>
<br/>


<pre>
<code class="sourceCode" id="sourceCode">&nbsp;package nl.tudelft.jpacman.board;
&nbsp;
&nbsp;
&nbsp;/**
&nbsp; * A top-down view of a matrix of {@link Square}s.
&nbsp; *
&nbsp; * @author Jeroen Roosen 
&nbsp; */
<b class="fc">&nbsp;public class Board {</b>
&nbsp;
&nbsp;    /**
&nbsp;     * The grid of squares with board[x][y] being the square at column x, row y.
&nbsp;     */
&nbsp;    private final Square[][] board;
&nbsp;
&nbsp;    /**
&nbsp;     * Creates a new board.
&nbsp;     *
&nbsp;     * @param grid
&nbsp;     *            The grid of squares with grid[x][y] being the square at column
&nbsp;     *            x, row y.
&nbsp;     */
&nbsp;    @SuppressWarnings(&quot;PMD.ArrayIsStoredDirectly&quot;)
<b class="fc">&nbsp;    Board(Square[][] grid) {</b>
<b class="fc">&nbsp;        assert grid != null;</b>
<b class="fc">&nbsp;        this.board = grid;</b>
<b class="fc">&nbsp;        assert invariant() : &quot;Initial grid cannot contain null squares&quot;;</b>
<b class="fc">&nbsp;    }</b>
&nbsp;
&nbsp;    /**
&nbsp;     * Whatever happens, the squares on the board can&#39;t be null.
&nbsp;     * @return false if any square on the board is null.
&nbsp;     */
&nbsp;    protected final boolean invariant() {
<b class="fc">&nbsp;        for (Square[] row : board) {</b>
<b class="fc">&nbsp;            for (Square square : row) {</b>
<b class="fc">&nbsp;                if (square == null) {</b>
<b class="nc">&nbsp;                    return false;</b>
&nbsp;                }
&nbsp;            }
&nbsp;        }
<b class="fc">&nbsp;        return true;</b>
&nbsp;    }
&nbsp;
&nbsp;    /**
&nbsp;     * Returns the number of columns.
&nbsp;     *
&nbsp;     * @return The width of this board.
&nbsp;     */
&nbsp;    public int getWidth() {
<b class="fc">&nbsp;        return board.length;</b>
&nbsp;    }
&nbsp;
&nbsp;    /**
&nbsp;     * Returns the number of rows.
&nbsp;     *
&nbsp;     * @return The height of this board.
&nbsp;     */
&nbsp;    public int getHeight() {
<b class="fc">&nbsp;        return board[0].length;</b>
&nbsp;    }
&nbsp;
&nbsp;    /**
&nbsp;     * Returns the square at the given &lt;code&gt;x,y&lt;/code&gt; position.
&nbsp;     *
&nbsp;     * Precondition: The &lt;code&gt;(x, y)&lt;/code&gt; coordinates are within the
&nbsp;     * width and height of the board.
&nbsp;     *
&nbsp;     * @param x
&nbsp;     *            The &lt;code&gt;x&lt;/code&gt; position (column) of the requested square.
&nbsp;     * @param y
&nbsp;     *            The &lt;code&gt;y&lt;/code&gt; position (row) of the requested square.
&nbsp;     * @return The square at the given &lt;code&gt;x,y&lt;/code&gt; position (never null).
&nbsp;     */
&nbsp;    public Square squareAt(int x, int y) {
<b class="fc">&nbsp;        assert withinBorders(x, y);</b>
<b class="fc">&nbsp;        Square result = board[x][y];</b>
<b class="fc">&nbsp;        assert result != null : &quot;Follows from invariant.&quot;;</b>
<b class="fc">&nbsp;        return result;</b>
&nbsp;    }
&nbsp;
&nbsp;    /**
&nbsp;     * Determines whether the given &lt;code&gt;x,y&lt;/code&gt; position is on this board.
&nbsp;     *
&nbsp;     * @param x
&nbsp;     *            The &lt;code&gt;x&lt;/code&gt; position (row) to test.
&nbsp;     * @param y
&nbsp;     *            The &lt;code&gt;y&lt;/code&gt; position (column) to test.
&nbsp;     * @return &lt;code&gt;true&lt;/code&gt; iff the position is on this board.
&nbsp;     */
&nbsp;    public boolean withinBorders(int x, int y) {
<b class="fc">&nbsp;        return x &gt;= 0 &amp;&amp; x &lt; getWidth() &amp;&amp; y &gt;= 0 &amp;&amp; y &lt; getHeight();</b>
&nbsp;    }
&nbsp;}
</code>
</pre>
</div>

<script type="text/javascript">
(function() {
    var msie = false, msie9 = false;
    /*@cc_on
      msie = true;
      @if (@_jscript_version >= 9)
        msie9 = true;
      @end
    @*/

    if (!msie || msie && msie9) {
      hljs.highlightAll()
      hljs.initLineNumbersOnLoad();
    }
})();
</script>

<div class="footer">
    
    <div style="float:right;">generated on 2023-04-11 19:39</div>
</div>
</body>
</html>
